#include <bits/stdc++.h>
using namespace std;

set<long long> s;

int main() {
   freopen("kte.in", "r", stdin);
   freopen("kte.out", "w", stdout); 
   ios :: sync_with_stdio(false), cin.tie(0);
   
   int T; cin >> T; while (T--) {
      long long x; cin >> x;
      auto p = s.find(x);
      if (p == s.end()) {
         s.insert(x);
      } else {
         s.erase(p);
      }
      int n = s.size(), ppp = 0;
      long long ans = 0;
      vector<long long> sum(n + 1);
      for (auto i : s) ppp++, sum[ppp] = sum[ppp - 1] + i;
      for (int i = 1; i < n; i++) {
         ans += min(sum[n - i + 1], sum[n] - sum[i]) - sum[n - i];
      } cout << ans << "\n";
   }
   return 0;
}

